package gui;

import java.util.ArrayList;

import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableRowSorter;

import util.ItemMarketOrderModel;
import util.MainMouseListener;
import data.EVEItem;
import data.EVESystem;
import data.ItemSystemCollection;

public class CollectionTabbedPane extends JTabbedPane {

  private ArrayList<ItemSystemCollection>  _collections;
  private MainMouseListener                _mouseListener;
  private ArrayList<ProductGroupSplitPane> _splitPanes;

  public CollectionTabbedPane(ArrayList<ItemSystemCollection> collections, MarketTable marketTable, MainMouseListener mouseListener, ListContextMenu contextMenu) {
    _collections = collections;
    _mouseListener = mouseListener;
    _splitPanes = new ArrayList<ProductGroupSplitPane>();
    addMouseListener(mouseListener);

    for (ItemSystemCollection collection : _collections) {
      ProductGroupSplitPane newPane = new ProductGroupSplitPane(collection, _mouseListener);
      addTab(collection.getUserName(), newPane);
      _splitPanes.add(newPane);
    }
  }

  public ItemSystemCollection getSelectedCollection() {
    return _collections.get(getSelectedIndex());
  }

  public ProductGroupSplitPane getSelectedPane() {
    return _splitPanes.get(getSelectedIndex());
  }

  public ArrayList<ProductGroupSplitPane> getPanes() {
    return _splitPanes;
  }

  public void addCollection(String name) {
    ItemSystemCollection collection = new ItemSystemCollection("unknown", name);
    _collections.add(collection);
    ProductGroupSplitPane newPane = new ProductGroupSplitPane(collection, _mouseListener);
    addTab(name, newPane);
    _splitPanes.add(newPane);
  }

  public void addSystem(EVESystem newSystem) {
    ProductGroupSplitPane currentPane = _splitPanes.get(getSelectedIndex());
    currentPane.addSystem(newSystem);
  }

  public void addItem(EVEItem newItem) {
    ProductGroupSplitPane currentPane = _splitPanes.get(getSelectedIndex());
    currentPane.addItem(newItem);
  }
}
